home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Table / Sources / TblFrame.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  24.0 KB  |  868 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                TblFrame.cpp
  4. //    Release Version:    $ 1.0d11 $ 
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Table.hpp"
  11.  
  12. // ----- TablePart Includes -----
  13.  
  14. #ifndef TBLFRAME_H
  15. #include "TblFrame.h"
  16. #endif
  17.  
  18. #ifndef TBLPART_H
  19. #include "TblPart.h"
  20. #endif
  21.  
  22. #ifndef TBLPROXY_H
  23. #include "TblProxy.h"
  24. #endif
  25.  
  26. #ifndef TBLSEL_H
  27. #include "TblSel.h"
  28. #endif
  29.  
  30. #ifndef TBLTRCKR_H
  31. #include "TblTrckr.h"
  32. #endif
  33.  
  34. #ifndef TBLCMDS_H
  35. #include "TblCmds.h"
  36. #endif
  37.  
  38. #ifndef TBLLINK_H
  39. #include "TblLink.h"
  40. #endif
  41.  
  42. // ----- Part Layer -----
  43.  
  44. #ifndef FWEDCMD_H
  45. #include "FWEdCmd.h"
  46. #endif
  47.  
  48. #ifndef FWPROXY_H
  49. #include "FWProxy.h"
  50. #endif
  51.  
  52. #ifndef FWUTIL_H
  53. #include "FWUtil.h"
  54. #endif
  55.  
  56. #ifndef FWITERS_H
  57. #include "FWIters.h"
  58. #endif
  59.  
  60. #ifndef FWFCTCLP_H
  61. #include "FWFctClp.h"
  62. #endif
  63.  
  64. // ----- OS Layer -----
  65.  
  66. #ifndef FWEVENT_H
  67. #include "FWEvent.h"
  68. #endif
  69.  
  70. #ifndef FWMNUBAR_H
  71. #include "FWMnuBar.h"
  72. #endif
  73.  
  74. #ifndef FWPOINT_H
  75. #include "FWPoint.h"
  76. #endif
  77.  
  78. #ifndef FWRECSHP_H
  79. #include "FWRecShp.h"
  80. #endif
  81.  
  82. #ifndef FWRECT_H
  83. #include "FWRect.h"
  84. #endif
  85.  
  86. #ifndef FWCFMRES_H
  87. #include "FWCFMRes.h"
  88. #endif
  89.  
  90. #ifndef FWRGNSHP_H
  91. #include "FWRgnShp.h"
  92. #endif
  93.  
  94. #ifndef FWODGEOM_H
  95. #include "FWODGeom.h"
  96. #endif
  97.  
  98. #ifndef FWCURSOR_H
  99. #include "FWCursor.h"
  100. #endif
  101.  
  102. // ----- Foundation Layer -----
  103.  
  104. #ifndef FWORDCOL_H
  105. #include "FWOrdCol.h"
  106. #endif
  107.  
  108. // ----- OpenDoc Includes -----
  109.  
  110. #ifndef SOM_ODClipboard_xh
  111. #include <Clipbd.xh>
  112. #endif
  113.  
  114. #ifndef SOM_ODDragItemIterator_xh
  115. #include <DgItmIt.xh>
  116. #endif
  117.  
  118. #ifndef SOM_ODDragAndDrop_xh
  119. #include <DragDrp.xh>
  120. #endif
  121.  
  122. #ifndef _ODTYPES_
  123. #include <ODTypes.h>
  124. #endif
  125.  
  126. #ifndef SOM_Module_OpenDoc_StdProps_defined
  127. #include <StdProps.xh>
  128. #endif
  129.  
  130. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  131. #include <StdTypes.xh>
  132. #endif
  133.  
  134. #ifndef SOM_ODStorageUnit_xh
  135. #include <StorageU.xh>
  136. #endif
  137.  
  138. #ifndef SOM_ODTransform_xh
  139. #include <Trnsform.xh>
  140. #endif
  141.  
  142. #ifndef SOM_ODSession_xh
  143. #include <ODSessn.xh>
  144. #endif
  145.  
  146. #ifndef SOM_ODDispatcher_xh
  147. #include <Disptch.xh>
  148. #endif
  149.  
  150. // ----- Macintosh Toolbox Includes -----
  151.  
  152. #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
  153. #include <Resources.h>
  154. #endif
  155.  
  156. //========================================================================================
  157. // Constants
  158. //========================================================================================
  159.  
  160. // ----- [HLX] need to move these somewhere -----
  161. const char kLeftArrow    = 0x1C;
  162. const char kRightArrow    = 0x1D;
  163. const char kUpArrow        = 0x1E;
  164. const char kDownArrow    = 0x1F;
  165. const char kDelKey        = 0x08;
  166. const char kFwdDelKey    = 0x7f;
  167.  
  168. //========================================================================================
  169. // RunTime Info
  170. //========================================================================================
  171.  
  172. #ifdef FW_BUILD_MAC
  173. #pragma segment odfTable
  174. #endif
  175.  
  176. //========================================================================================
  177. //    class CTableFrame
  178. //========================================================================================
  179.  
  180. //----------------------------------------------------------------------------------------
  181. //    CTableFrame::CTableFrame
  182. //----------------------------------------------------------------------------------------
  183.  
  184. CTableFrame::CTableFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CTablePart* tablePart) :
  185.     FW_CEmbeddingFrame(ev, odFrame, presentation, tablePart),
  186.     fTablePart(NULL),
  187.     fGridShown(TRUE),
  188.     fSelectFrame(FW_kZeroRect, FW_kFrame, FW_PInk(FW_kXOr), FW_PStyle(FW_IntToFixed(2)))
  189. {
  190.     SetDroppable(ev, fGridShown);
  191.     
  192.     fTablePart = tablePart;
  193.     fDraggedCell.fX = fDraggedCell.fY = -1;
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    CTableFrame::~CTableFrame
  198. //----------------------------------------------------------------------------------------
  199.  
  200. CTableFrame::~CTableFrame()
  201. {
  202. }
  203.  
  204. //----------------------------------------------------------------------------------------
  205. //    CTableFrame::GetSelection
  206. //----------------------------------------------------------------------------------------
  207.  
  208. CTableSelection* CTableFrame::GetSelection(Environment* ev) const
  209. {
  210.     return (CTableSelection*)GetPresentation(ev)->GetSelection(ev);
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. //    CTableFrame::DoMenu
  215. //----------------------------------------------------------------------------------------
  216.  
  217. FW_Boolean CTableFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  218. {
  219.     FW_Boolean result = TRUE;
  220.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  221.  
  222.     switch(commandID)
  223.     {
  224.         case cHideShowGrid:
  225.             HideShowGrid(ev);
  226.             break;
  227.  
  228.         default:
  229.             result = FALSE;
  230.             break;
  231.     }
  232.     
  233.     return result;
  234. }
  235.  
  236. //----------------------------------------------------------------------------------------
  237. // CTableFrame::HideShowGrid
  238. //----------------------------------------------------------------------------------------
  239.  
  240. void CTableFrame::HideShowGrid(Environment* ev)
  241. {
  242.     fGridShown = !fGridShown;
  243.     SetDroppable(ev, fGridShown);
  244.     
  245.     FW_CFrameFacetIterator ite(ev, this);
  246.     for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  247.     {
  248.         FW_CFacetIterator ite2(ev, facet, kODChildrenOnly, kODFrontToBack);
  249.         for (ODFacet* embeddedFacet = ite2.First(ev); ite2.IsNotComplete(ev); embeddedFacet = ite2.Next(ev))
  250.         {
  251.             embeddedFacet->SetSelected(ev, fGridShown);
  252.         }
  253.         
  254.         FW_CFacetContext fc(ev, facet);
  255.         
  256.         if (IsActive(ev))
  257.             DrawSelectBorder(ev, fc, GetSelection(ev)->GetCell());
  258.             
  259.         DrawGrid(ev, fc, fGridShown);
  260.     }    
  261. }
  262.  
  263. //----------------------------------------------------------------------------------------
  264. // CTableFrame::Draw
  265. //----------------------------------------------------------------------------------------
  266.  
  267. void CTableFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  268. {
  269.     FW_CFacetContext fc(ev, odFacet, invalidShape);
  270.     
  271.     FW_CRect invalidRect;
  272.     fc.GetClipRect(invalidRect);
  273.     
  274.     // Erase invalid portion of the frame
  275.     FW_CRectShape::RenderRect(fc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  276.     
  277.     // Draw the table grid
  278.     if (fGridShown)
  279.         DrawGrid(ev, fc, TRUE);    
  280.  
  281.     // Draw the selection
  282.     if (IsActive(ev) && fGridShown)
  283.         DrawSelectBorder(ev, fc, GetSelection(ev)->GetCell());
  284.  
  285.     //--- Draw Link borders ---
  286.     FW_CAcquiredODWindow aqODWindow = odFacet->GetFrame(ev)->AcquireWindow(ev);
  287.     if (aqODWindow->ShouldShowLinks(ev))
  288.     {
  289.         //--- Draw borders around link sources ---
  290.         FW_CPartPublishIterator siter(fTablePart);
  291.         for (CTablePublishLink* slink = (CTablePublishLink*)siter.First(); siter.IsNotComplete(); 
  292.                 slink = (CTablePublishLink*)siter.Next())
  293.         {
  294.             DrawLinkBorder(ev, slink->GetCell(ev), fc, TRUE);
  295.         }
  296.  
  297.         //--- Draw borders around link destinations ---
  298.         FW_CPartSubscribeIterator iter(fTablePart);
  299.         for (CTableSubscribeLink* link = (CTableSubscribeLink*)iter.First(); iter.IsNotComplete(); 
  300.                 link = (CTableSubscribeLink*)iter.Next())
  301.         {
  302.             DrawLinkBorder(ev, link->GetCell(ev), fc, FALSE);
  303.         }
  304.     }
  305. }
  306.  
  307. //----------------------------------------------------------------------------------------
  308. //    CTableFrame::DrawSelectBorder
  309. //----------------------------------------------------------------------------------------
  310.  
  311. void CTableFrame::DrawSelectBorder(Environment* ev, FW_CFacetContext& fc, const CCell& cell)
  312. {
  313.     FW_CRect rect;
  314.     fTablePart->FindRect(cell, rect);
  315.     rect.Inset(FW_IntToFixed(-1), FW_IntToFixed(-1));
  316.     
  317.     fSelectFrame.SetGeometry(rect);
  318.     fSelectFrame.Render(fc);
  319. }
  320.  
  321. //---------------------------------------------------------------------------------------
  322. //    CTableFrame::DrawGrid
  323. //---------------------------------------------------------------------------------------
  324.  
  325. void CTableFrame::DrawGrid(Environment* ev, FW_CGraphicContext& gc, FW_Boolean gray)
  326. {
  327.     // Get the frame's rect at (0,0), inset by margins
  328.     FW_CRect rect;
  329.     this->GetRect(ev, rect);
  330.     
  331.     // Draw the table grid
  332.     FW_CLineShape lineShape;
  333.     lineShape.GetStyle()->SetPattern(gray ? FW_kGrayPat : FW_kWhitePat);
  334.         
  335.     FW_CFixed xy;
  336.     short rc;
  337.     for(xy = rect.top, rc = 0; xy < rect.bottom; xy += fTablePart->GetHeight(rc++) + kBorderHeight)
  338.     {
  339.         lineShape.SetLineStart(rect.left, xy);
  340.         lineShape.SetLineEnd(rect.right, xy);
  341.         lineShape.Render(gc);
  342.     }
  343.     
  344.     for(xy = rect.left, rc = 0;  xy < rect.right; xy += fTablePart->GetWidth(rc++) + kBorderHeight)
  345.     {
  346.         lineShape.SetLineStart(xy, rect.top);
  347.         lineShape.SetLineEnd(xy, rect.bottom);
  348.         lineShape.Render(gc);
  349.     }
  350. }
  351.  
  352. //---------------------------------------------------------------------------------------
  353. //    CTableFrame::DoAdjustMenus
  354. //---------------------------------------------------------------------------------------
  355.  
  356. FW_Boolean CTableFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  357. {
  358.     if (hasMenuFocus)
  359.     {
  360.         FW_Boolean hasSelection = !GetSelection(ev)->IsEmpty(ev);
  361.         
  362.         menuBar->EnableAndToggleCommand(ev, cHideShowGrid, TRUE, fGridShown);
  363.         
  364.         // If an embedded part is selected, change Copy item to "Copy Part"
  365.         menuBar->SetItemString(ev, kODCommandCopy, hasSelection ? FW_CString32("Copy Part") : FW_CString32("Copy"));
  366.  
  367.         menuBar->EnableCommand(ev, kODCommandCopy, fGridShown && hasSelection);
  368.         menuBar->EnableCommand(ev, kODCommandClear, fGridShown && hasSelection);
  369.         menuBar->EnableCommand(ev, kODCommandCut, fGridShown && hasSelection);
  370.  
  371.         menuBar->EnableCommand(ev, kODCommandInsert, fGridShown);
  372.  
  373.         // Check clipboard for paste
  374.         menuBar->EnableCommand(ev, kODCommandPaste, fGridShown && HasPropertyOnClipboard(ev, kODPropContentFrame, NULL));
  375.  
  376.         menuBar->EnableCommand(ev, kODCommandPasteAs, fGridShown && HasPropertyOnClipboard(ev, kODPropLinkSpec, kODLinkSpec));
  377.     }
  378.     
  379.     return FALSE;
  380. }
  381.  
  382. //----------------------------------------------------------------------------------------
  383. //    CTableFrame::FrameShapeChanged
  384. //----------------------------------------------------------------------------------------
  385.  
  386. void CTableFrame::FrameShapeChanged(Environment* ev)
  387. {
  388.     FW_CEmbeddingFrame::FrameShapeChanged(ev);
  389.     
  390.     // ----- Recalculate the clip of all my embedded facets -----
  391.     FW_CFacetClipper facetClipper(ev, fTablePart);
  392.     facetClipper.Clip(ev, GetPresentation(ev), NULL);
  393. }
  394.  
  395. //----------------------------------------------------------------------------------------
  396. //    CTableFrame::DoCharKey
  397. //----------------------------------------------------------------------------------------
  398.  
  399. FW_Boolean CTableFrame::DoCharKey(Environment* ev, const FW_CCharKeyEvent& theCharKeyEvent)
  400. {
  401.     FW_Boolean    tWasHandled = FALSE;
  402.     CCell        cell = this->GetSelection(ev)->GetCell();
  403.     CCell        size = fTablePart->GetSize();
  404.     
  405.     switch (theCharKeyEvent.GetChar(ev))
  406.     {
  407.         case kLeftArrow:
  408.             if(cell.fX > 0)
  409.             {
  410.                 cell.fX -= 1;
  411.                 this->SelectCell(ev, cell, TRUE);
  412.                 tWasHandled = TRUE;
  413.             }
  414.             break;
  415.         case kRightArrow:
  416.             if(cell.fX < size.fX - 1)
  417.             {
  418.                 cell.fX += 1;
  419.                 this->SelectCell(ev, cell, TRUE);
  420.                 tWasHandled = TRUE;
  421.             }
  422.             break;
  423.         case kUpArrow:
  424.             if(cell.fY > 0)
  425.             {
  426.                 cell.fY -= 1;
  427.                 this->SelectCell(ev, cell, TRUE);
  428.                 tWasHandled = TRUE;
  429.             }
  430.             break;
  431.         case kDownArrow:
  432.             if(cell.fY < size.fY - 1)
  433.             {
  434.                 cell.fY += 1;
  435.                 this->SelectCell(ev, cell, TRUE);
  436.                 tWasHandled = TRUE;
  437.             }
  438.             break;
  439.  
  440.         case kDelKey:
  441.         case kFwdDelKey:
  442.             if(this == GetPart()->GetActiveFrame(ev))
  443.             {
  444.                 FW_CEditCommand* cmd = this->NewEditCommand(ev, kODCommandClear);
  445.                 if (cmd)
  446.                     GetPart()->ExecuteCommand(ev, cmd);
  447.                 tWasHandled = TRUE;
  448.             }
  449.             break;
  450.     }
  451.  
  452.     return tWasHandled;
  453. }
  454.  
  455. //----------------------------------------------------------------------------------------
  456. //    CTableFrame::DoMouseDown
  457. //----------------------------------------------------------------------------------------
  458.  
  459. FW_Boolean CTableFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  460. {
  461.     if (!fGridShown)
  462.         return TRUE;
  463.         
  464.     if (GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE))
  465.     {
  466.         Drag(ev, theMouseEvent);
  467.     }
  468.     else 
  469.     {    
  470.         FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  471.  
  472.         CCell cell;
  473.         ETableLoc tl = fTablePart->HitTest(ev, this, where, cell);
  474.         
  475.         if (tl != kTLNone && tl != kTLCell)
  476.             this->Resize(ev, theMouseEvent, cell, tl);
  477.     }
  478.     
  479.     return TRUE;
  480. }
  481.     
  482. //----------------------------------------------------------------------------------------
  483. //    CTableFrame::DoMouseDownInEmbeddedFrameBorder
  484. //----------------------------------------------------------------------------------------
  485.  
  486. FW_Boolean CTableFrame::DoMouseDownInEmbeddedFrameBorder(Environment* ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
  487. {
  488.     if (fGridShown)
  489.         this->Drag(ev, theBorderMouseEvent);
  490.     
  491.     return TRUE;
  492. }
  493.  
  494. //----------------------------------------------------------------------------------------
  495. //    CTableFrame::SelectCell
  496. //----------------------------------------------------------------------------------------
  497.  
  498. void CTableFrame::SelectCell(Environment* ev, const CCell& cell, FW_Boolean drawNow)
  499. {
  500.     GetSelection(ev)->Select(ev, cell, drawNow);
  501. }
  502.  
  503. //----------------------------------------------------------------------------------------
  504. //    CTableFrame::Resize
  505. //----------------------------------------------------------------------------------------
  506.  
  507. FW_Boolean CTableFrame::Resize(Environment* ev, 
  508.                                const FW_CMouseEvent& theMouseEvent,
  509.                                const CCell& cell,
  510.                                ETableLoc tl)
  511. {
  512.     FW_ASSERT(tl != kTLNone && tl != kTLCell);
  513.     FW_Boolean result = FALSE;
  514.  
  515.     // maximum rectangle
  516.     FW_CRect maxRect;
  517.     this->GetRect(ev, maxRect);
  518.     maxRect.right  -= kPenWidth;
  519.     maxRect.bottom -= kPenHeight;
  520.  
  521.     // Location of borders
  522.     FW_CRect cellRect;
  523.     fTablePart->FindRect(cell, cellRect);
  524.     
  525.     FW_CPoint borders;
  526.     if ((tl & kTLLeftBorder) != 0)
  527.     {
  528.         maxRect.left = ((cell.fX == 0) ? cellRect.left : fTablePart->FindLeft(cell.fX - 1)) + kBorderWidth;
  529.         borders.x = cellRect.left;
  530.     }
  531.     else 
  532.     {
  533.         maxRect.left = cellRect.left + kBorderWidth;
  534.         borders.x = cellRect.right;
  535.     }
  536.         
  537.     if ((tl & kTLTopBorder) != 0)
  538.     {
  539.         maxRect.top = ((cell.fY == 0) ? cellRect.top : fTablePart->FindTop(cell.fY - 1)) + kBorderHeight;
  540.         borders.y = cellRect.top;
  541.     }
  542.     else 
  543.     {
  544.         maxRect.top = cellRect.top + kBorderHeight;
  545.         borders.y = cellRect.bottom;
  546.     }
  547.     
  548.  
  549.     // Create a tracker for the grid lines
  550.     CGridLineTracker tracker(ev, this, theMouseEvent.GetFacet(ev), tl, maxRect, borders);
  551.  
  552.     if (tracker.Track(ev, theMouseEvent))
  553.     {
  554.         // Set the new cell size
  555.         FW_CPoint delta = tracker.GetNewBorders() - tracker.GetOldBorders();
  556.         if (delta.x || delta.y)
  557.         {
  558.             fTablePart->Resize(ev, cell, tl, delta);
  559.             result = TRUE;
  560.         }
  561.     }
  562.  
  563.     return result;
  564. }
  565.  
  566. //----------------------------------------------------------------------------------------
  567. //    CTableFrame::Drag
  568. //----------------------------------------------------------------------------------------
  569.  
  570. FW_Boolean CTableFrame::Drag(Environment* ev, const FW_CMouseEvent& event)
  571. {
  572.     fDraggedCell = GetSelection(ev)->GetCell();
  573.     
  574.     FW_Boolean result = FW_CEmbeddingFrame::Drag(ev, event);
  575.     
  576.     fDraggedCell.fX = fDraggedCell.fY = -1;
  577.     
  578.     return result;
  579. }
  580.  
  581. //----------------------------------------------------------------------------------------
  582. //    CTableFrame::FocusStateChanged
  583. //----------------------------------------------------------------------------------------
  584.  
  585. void CTableFrame::FocusStateChanged(Environment* ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
  586. {    
  587.     FW_CEmbeddingFrame::FocusStateChanged(ev, focus, newState, newOwner);
  588.  
  589.     if (focus == FW_CPart::gSelectionFocusToken)
  590.     {                
  591.         FW_CFrameFacetIterator ite(ev, this);
  592.         for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  593.         {
  594.             if (fGridShown)
  595.             {
  596.                 FW_CFacetContext fc(ev, facet);
  597.                 DrawSelectBorder(ev, fc, GetSelection(ev)->GetCell());
  598.             }
  599.         }
  600.     }
  601. }
  602.  
  603. //----------------------------------------------------------------------------------------
  604. //    CTableFrame::AdjustCursor
  605. //----------------------------------------------------------------------------------------
  606.  
  607. FW_Boolean CTableFrame::AdjustCursor(Environment* ev, ODFacet* odFacet, const FW_CPoint& where)
  608. {
  609.     FW_Boolean cursorAdjusted = FALSE;
  610.     
  611.     //     I don't want the Open Hand Cursor if I have the grid hidden because I am not supposed to
  612.     //    be able to move anything
  613.     if (fGridShown)
  614.         cursorAdjusted = FW_CEmbeddingFrame::AdjustCursor(ev, odFacet, where);
  615.     
  616.     if (!cursorAdjusted && fGridShown)
  617.     {
  618.         CCell cell;
  619.         ETableLoc tl = fTablePart->HitTest(ev, this, where, cell);
  620.             
  621.         cursorAdjusted = TRUE;
  622.         
  623.         if (tl == kTLCell || tl == kTLNone)
  624.             FW_gArrowCursor.Select();
  625.         else if (tl == kTLLeftBorder || tl == kTLRightBorder)
  626.             FW_gSizeWECursor.Select();
  627.         else if (tl == kTLTopBorder || tl == kTLBottomBorder)
  628.             FW_gSizeNSCursor.Select();
  629.         else 
  630.             FW_gSizeNWSECursor.Select();
  631.     }
  632.     
  633.     return cursorAdjusted;
  634. }
  635.  
  636. //----------------------------------------------------------------------------------------
  637. //    CTableFrame::GetRect
  638. //----------------------------------------------------------------------------------------
  639.  
  640. void CTableFrame::GetRect(Environment* ev, FW_CRect& rect) const
  641. {
  642.     rect = GetBounds(ev);
  643.     rect.left += kHMargin;
  644.     rect.top += kVMargin;
  645. }
  646.  
  647. //----------------------------------------------------------------------------------------
  648. //    CTableFrame::NewDropCommand
  649. //----------------------------------------------------------------------------------------
  650.  
  651. FW_CDropCommand* CTableFrame::NewDropCommand(Environment* ev,
  652.                                             FW_CFrame* frame,
  653.                                             ODDragItemIterator* dropInfo, 
  654.                                             ODFacet* odFacet, 
  655.                                             const FW_CPoint& dropPoint)
  656. {
  657.     FW_ASSERT(frame == this);
  658.     
  659.     CCell dropCell;
  660.     fTablePart->HitTest(ev, this, dropPoint, dropCell);
  661.  
  662.     if (dropCell == fDraggedCell)
  663.         return NULL;
  664.     else
  665.         return FW_NEW(CCellDropCommand, (ev, fTablePart, this,
  666.                                          dropInfo, odFacet, dropPoint,
  667.                                         dropCell, fDraggedCell));
  668. }
  669.  
  670. //----------------------------------------------------------------------------------------
  671. //    CTableFrame::NewDropTracker
  672. //----------------------------------------------------------------------------------------
  673.  
  674. FW_CDropTracker* CTableFrame::NewDropTracker(Environment *ev, FW_CView* view, ODFacet* facet)
  675. {
  676.     return FW_NEW(CTableDropTracker, (ev, fTablePart, this, facet, fDraggedCell));
  677. }
  678.  
  679. //----------------------------------------------------------------------------------------
  680. //    CTableFrame::CreateEmbeddedFacet
  681. //----------------------------------------------------------------------------------------
  682.  
  683. ODFacet* CTableFrame::CreateEmbeddedFacet(Environment* ev,
  684.                                         ODFacet* embeddingFacet,
  685.                                         FW_MProxy* proxy,
  686.                                         ODFrame* embeddedFrame,
  687.                                         ODShape* proposedClipShape)
  688. {
  689.     CCell cell = ((CTableProxy*)proxy)->GetCell();
  690.     
  691.     FW_CRect rect;
  692.     fTablePart->FindRect(cell, rect);
  693.     
  694.     FW_CAcquiredODTransform aqExternalTransform = ::FW_NewODTransform(ev, rect.TopLeft());
  695.  
  696.     return embeddingFacet->CreateEmbeddedFacet(ev,
  697.                                                 embeddedFrame,
  698.                                                 proposedClipShape,
  699.                                                 aqExternalTransform,
  700.                                                 NULL,                    // Canvas
  701.                                                 NULL,                    // biasCanvas
  702.                                                 NULL,                    // siblingFacet
  703.                                                 kODFrameInFront);
  704. }
  705.  
  706. //----------------------------------------------------------------------------------------
  707. //    CTableFrame::EmbedSingleFrame
  708. //----------------------------------------------------------------------------------------
  709.  
  710. void CTableFrame::EmbedSingleFrame(Environment* ev,
  711.                                 ODPart* odEmbeddedPart, 
  712.                                 ODFrame* odEmbeddedFrame,     // might be null
  713.                                 ODShape* frameShape)
  714. {
  715.     FW_UNUSED(frameShape);
  716.     
  717.     CCell selectionCell = GetSelection(ev)->GetCell();
  718.     
  719.     CTableProxy* proxy = fTablePart->CellToProxy(ev, selectionCell);
  720.     if (proxy)
  721.         proxy->DetachEmbeddedFrames(ev);
  722.     
  723.     FW_CRect rect;
  724.     fTablePart->FindRect(selectionCell, rect);
  725.     rect.Place(FW_kZeroPoint);
  726.  
  727.     FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, rect);
  728.  
  729.     // ----- Create the proxy -----
  730.     CTableProxy* newProxy = new CTableProxy(ev, fTablePart, GetPresentation(ev));
  731.     newProxy->SetCell(selectionCell);
  732.     
  733.     // ----- Add the newProxy to the part -----
  734.     fTablePart->AddProxy(newProxy);
  735.     
  736.     // ----- Embed the part or the frame -----
  737.     GetPresentation(ev)->Embed(ev, 
  738.                             odEmbeddedPart,
  739.                             odEmbeddedFrame,    
  740.                             newProxy,
  741.                             aqShape,
  742.                               fTablePart->GetSession(ev)->Tokenize(ev, kODViewAsFrame), 
  743.                               fTablePart->GetSession(ev)->Tokenize(ev, kODPresDefault),
  744.                               0,            // groupe id
  745.                               FALSE);        // sub frame
  746.  
  747.     GetSelection(ev)->InvalidateSelection(ev);
  748.  
  749.     // ----- Delete the old proxy if there was one there
  750.     if (proxy != NULL)
  751.     {
  752.         fTablePart->RemoveProxy(proxy);
  753.         delete proxy;
  754.     }
  755. }
  756.  
  757. //----------------------------------------------------------------------------------------
  758. // CTableFrame::NewEditCommand
  759. //----------------------------------------------------------------------------------------
  760.  
  761. FW_CEditCommand* CTableFrame::NewEditCommand(Environment* ev, ODCommandID commandID)
  762. {
  763.     return FW_NEW(CTableEditCommand, (ev,
  764.                                       commandID,
  765.                                       fTablePart,
  766.                                       this,
  767.                                       this->GetSelection(ev)));
  768. }
  769.  
  770. //----------------------------------------------------------------------------------------
  771. // CTableFrame::NewDragCommand
  772. //----------------------------------------------------------------------------------------
  773.  
  774. FW_CDragCommand* CTableFrame::NewDragCommand(Environment *ev, FW_CFrame* theFrame)
  775. {
  776.     return FW_NEW(CCellDragCommand, (ev, fTablePart, theFrame, this->GetSelection(ev)));
  777. }
  778.  
  779. //----------------------------------------------------------------------------------------
  780. // CTableFrame::MoveProxy
  781. //----------------------------------------------------------------------------------------
  782.  
  783. void CTableFrame::MoveProxy(Environment* ev, CTableProxy* proxy, const CCell& destCell)
  784. {
  785.     // Invalidate the source cell
  786.     FW_CRect rect;
  787.     CCell srcCell = proxy->GetCell();
  788.     fTablePart->FindRect(srcCell, rect);
  789.     this->GetPresentation(ev)->Invalidate(ev, rect);
  790.  
  791.     proxy->MoveEmbeddedFrames(ev, destCell);
  792.     proxy->SetCell(destCell);
  793.     this->SelectCell(ev, destCell, FALSE);
  794.  
  795.     // Invalidate the destination cell
  796.     fTablePart->FindRect(destCell, rect);
  797.     this->GetPresentation(ev)->Invalidate(ev, rect);
  798. }
  799.  
  800. //---------------------------------------------------------------------------------------
  801. //    CTableFrame::DrawLinkBorder
  802. //---------------------------------------------------------------------------------------
  803.  
  804. void CTableFrame::DrawLinkBorder(Environment* ev, 
  805.                                  const CCell& cell, 
  806.                                  FW_CFacetContext& fc,
  807.                                  FW_Boolean isSourceLink)
  808. {
  809.     FW_CRect rect;
  810.     fTablePart->FindRect(cell, rect);
  811.     FW_CRectShape rectShape(rect, FW_kFrame);
  812.     if (isSourceLink)
  813.     {
  814.         rectShape.GetUnSharedStyle()->SetPattern(FW_kLightGrayPat);
  815.         rectShape.GetUnSharedInk()->SetTransferMode(FW_kOr);
  816.     }
  817.     else
  818.     {
  819.         rectShape.GetUnSharedStyle()->SetPattern(FW_kAntPat);
  820.         rectShape.GetUnSharedInk()->SetTransferMode(FW_kXOr);
  821.     }
  822.     rectShape.GetUnSharedStyle()->SetPenSize(FW_IntToFixed(3));
  823.     rectShape.Inset(FW_IntToFixed(1), FW_IntToFixed(1));
  824.     rectShape.Render(fc);
  825. }
  826.  
  827. //---------------------------------------------------------------------------------------
  828. //    CTableFrame::FacetAdded
  829. //---------------------------------------------------------------------------------------
  830. void CTableFrame::FacetAdded(Environment* ev, ODFacet* facet)
  831. {
  832.     FW_CEmbeddingFrame::FacetAdded(ev, facet);    // call inherited
  833.  
  834.     // We need to register any link destinations that were just internalized.
  835.     fTablePart->RegisterSubscribers(ev);
  836. }
  837.  
  838. //---------------------------------------------------------------------------------------
  839. //    CTableFrame::ShowPartInfo
  840. //---------------------------------------------------------------------------------------
  841. void CTableFrame::ShowPartInfo(Environment* ev)
  842. {
  843.     if (fTablePart->ShowLinkInfo(ev, this)) return;
  844.  
  845.     // Table part didn't handle it, so call inherited
  846.     FW_CEmbeddingFrame::ShowPartInfo(ev);
  847. }
  848.  
  849. //---------------------------------------------------------------------------------------
  850. //    CTableFrame::RevealFrame
  851. //---------------------------------------------------------------------------------------
  852. FW_Boolean CTableFrame::RevealFrame(Environment *ev, 
  853.                                     ODFrame* embeddedFrame, 
  854.                                     ODShape* revealShape)
  855. {
  856.     FW_UNUSED(revealShape);
  857.  
  858.     // Change table selection to the cell of the embedded frame
  859.     CTableProxy* proxy = (CTableProxy*) this->GetProxy(ev, embeddedFrame);
  860.     if (proxy)
  861.     {
  862.         this->SelectCell(ev, proxy->GetCell(), TRUE);
  863.         return TRUE;
  864.     }
  865.  
  866.     return FALSE;
  867. }
  868.